package ro.bluecube.admlocal.gui.commons;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;


public abstract class AbstractController implements FormListener{
	private AbstractController parent;
	private Collection subControllers;
	
	public abstract void activate(Map context);
	
	public abstract void perform(FormEvent e);
	public abstract void updateController(FormEvent e);
	
	public void performFormEvent(FormEvent e) {
			perform((FormEvent)e);
	}

	public void setParent(AbstractController parent){
		this.parent = parent;
	}
	
	public void addSubController(AbstractController controller){
		if (subControllers==null){
			subControllers = new ArrayList();
		}
		subControllers.add(controller);
	}
	
	public void notifyParentController(FormEvent event){
		if (parent!=null){
			parent.updateController(event);
		}
	}
	
	public void notifySubControllers(FormEvent event){
		for (Iterator iter = subControllers.iterator(); iter.hasNext();) {
			AbstractController element = (AbstractController) iter.next();
			element.updateController(event);
		}
	}
}
